import { Injectable } from '@nestjs/common';
import { CreateDirectoryDto } from './dto/create-directory.dto';
import { UpdateDirectoryDto } from './dto/update-directory.dto';
import { PrismaService } from '@/prisma/prisma.service';

@Injectable()
export class DirectoryService {
  constructor(private prisma: PrismaService) {}
  async create(dto: CreateDirectoryDto) {
    const directory = await this.prisma.directory.create({
      data: {
        name: dto.name,
        projectId: +dto.projectId,
        parentId: +dto.parentId,
      },
    });
    return directory;
  }

  async findAll() {
    return await this.prisma.directory.findMany({
      where: {
        projectId: 3,
      },
    });
  }

  async findOne(id: number) {
    return await this.prisma.directory.findFirst({
      where: {
        id,
      },
    });
  }

  async update(id: number, dto: UpdateDirectoryDto) {
    const newdirectory = await this.prisma.directory.update({
      where: {
        id,
      },
      data: {
        name: dto.name,
      },
    });
    return newdirectory;
  }

  async remove(id: number) {
    return await this.prisma.directory.delete({
      where: {
        id,
      },
    });
  }
}
